package com.briup.cms.service.impl;

import com.briup.cms.bean.BaseConfig;
import com.briup.cms.dao.BaseConfigExtendMapper;
import com.briup.cms.dao.BaseConfigMapper;
import com.briup.cms.exception.CustomerException;
import com.briup.cms.service.IBaseConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseConfigServiceImpl implements IBaseConfigService {
    @Autowired
    private BaseConfigMapper baseConfigMapper;
    @Override
    public void saveConfig(BaseConfig baseConfig) throws CustomerException {

        baseConfig.setConfigStatus(0);
        baseConfigMapper.insert(baseConfig);
    }

    @Override
    public void updateConfig(BaseConfig baseConfig) throws CustomerException {

        baseConfigMapper.updateByPrimaryKey(baseConfig);
    }


    @Override
    public void deleteById(int id) throws CustomerException {

        baseConfigMapper.deleteByPrimaryKey(id);
    }

    @Autowired
    private BaseConfigExtendMapper mapper;
    @Override
    public PageInfo<BaseConfig> findAllWithPage(int pageNum, int pageSize) throws CustomerException {
        PageHelper.startPage(pageNum,pageSize,true);
        List<BaseConfig> list =mapper.findAll();
        PageInfo<BaseConfig> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public BaseConfig currentConfigYes() throws CustomerException {
        BaseConfig baseConfig=mapper.SelectCurrentConfigYes();
        return baseConfig;
    }

    @Override
    public void changeConfigStatus(int id, int status) throws CustomerException {

        mapper.changeConfigStatus(id, status);
    }
}
